Public Class frmDeploymentZone
    Inherits System.Windows.Forms.Form

    Const c_Module As String = "frmDeploymentZone"

    Private ptrCGD As cmplib01.CampaignerGameData
    Private ptrDeploymentZone As cmplib01.DeploymentZone
    Private m_CancelPressed As Boolean

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlObjectiveProperties As System.Windows.Forms.Panel
    Friend WithEvents lblDeploymentZoneName As System.Windows.Forms.Label
    Friend WithEvents txtDeploymentZoneName As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents chkIsActive As System.Windows.Forms.CheckBox
    Friend WithEvents optCapturable As System.Windows.Forms.RadioButton
    Friend WithEvents optNotCapturable As System.Windows.Forms.RadioButton
    Friend WithEvents cboCaptureEvent As System.Windows.Forms.ComboBox
    Friend WithEvents btnOk As System.Windows.Forms.Button
    Friend WithEvents txtMaxTotalDeployment As System.Windows.Forms.TextBox
    Friend WithEvents txtMaxDeploymentPerTurn As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.pnlObjectiveProperties = New System.Windows.Forms.Panel
        Me.txtMaxTotalDeployment = New System.Windows.Forms.TextBox
        Me.txtMaxDeploymentPerTurn = New System.Windows.Forms.TextBox
        Me.cboCaptureEvent = New System.Windows.Forms.ComboBox
        Me.optNotCapturable = New System.Windows.Forms.RadioButton
        Me.optCapturable = New System.Windows.Forms.RadioButton
        Me.chkIsActive = New System.Windows.Forms.CheckBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.lblDeploymentZoneName = New System.Windows.Forms.Label
        Me.txtDeploymentZoneName = New System.Windows.Forms.TextBox
        Me.btnOk = New System.Windows.Forms.Button
        Me.pnlObjectiveProperties.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlObjectiveProperties
        '
        Me.pnlObjectiveProperties.BackColor = System.Drawing.SystemColors.ControlLight
        Me.pnlObjectiveProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlObjectiveProperties.Controls.Add(Me.txtMaxTotalDeployment)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtMaxDeploymentPerTurn)
        Me.pnlObjectiveProperties.Controls.Add(Me.cboCaptureEvent)
        Me.pnlObjectiveProperties.Controls.Add(Me.optNotCapturable)
        Me.pnlObjectiveProperties.Controls.Add(Me.optCapturable)
        Me.pnlObjectiveProperties.Controls.Add(Me.chkIsActive)
        Me.pnlObjectiveProperties.Controls.Add(Me.Label6)
        Me.pnlObjectiveProperties.Controls.Add(Me.Label5)
        Me.pnlObjectiveProperties.Controls.Add(Me.Label4)
        Me.pnlObjectiveProperties.Controls.Add(Me.Label3)
        Me.pnlObjectiveProperties.Controls.Add(Me.Label1)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblDeploymentZoneName)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtDeploymentZoneName)
        Me.pnlObjectiveProperties.Location = New System.Drawing.Point(8, 8)
        Me.pnlObjectiveProperties.Name = "pnlObjectiveProperties"
        Me.pnlObjectiveProperties.Size = New System.Drawing.Size(248, 256)
        Me.pnlObjectiveProperties.TabIndex = 2
        '
        'txtMaxTotalDeployment
        '
        Me.txtMaxTotalDeployment.Location = New System.Drawing.Point(112, 224)
        Me.txtMaxTotalDeployment.Name = "txtMaxTotalDeployment"
        Me.txtMaxTotalDeployment.Size = New System.Drawing.Size(120, 20)
        Me.txtMaxTotalDeployment.TabIndex = 22
        Me.txtMaxTotalDeployment.Text = "0"
        Me.txtMaxTotalDeployment.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'txtMaxDeploymentPerTurn
        '
        Me.txtMaxDeploymentPerTurn.Location = New System.Drawing.Point(112, 184)
        Me.txtMaxDeploymentPerTurn.Name = "txtMaxDeploymentPerTurn"
        Me.txtMaxDeploymentPerTurn.Size = New System.Drawing.Size(120, 20)
        Me.txtMaxDeploymentPerTurn.TabIndex = 21
        Me.txtMaxDeploymentPerTurn.Text = "0"
        Me.txtMaxDeploymentPerTurn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'cboCaptureEvent
        '
        Me.cboCaptureEvent.Items.AddRange(New Object() {"Changes Ownership", "Hold", "Destroyed"})
        Me.cboCaptureEvent.Location = New System.Drawing.Point(112, 144)
        Me.cboCaptureEvent.Name = "cboCaptureEvent"
        Me.cboCaptureEvent.Size = New System.Drawing.Size(120, 21)
        Me.cboCaptureEvent.TabIndex = 20
        Me.cboCaptureEvent.Text = "Changes Ownership"
        '
        'optNotCapturable
        '
        Me.optNotCapturable.Location = New System.Drawing.Point(112, 112)
        Me.optNotCapturable.Name = "optNotCapturable"
        Me.optNotCapturable.Size = New System.Drawing.Size(104, 16)
        Me.optNotCapturable.TabIndex = 19
        Me.optNotCapturable.Text = "Not Capturable"
        '
        'optCapturable
        '
        Me.optCapturable.Checked = True
        Me.optCapturable.Location = New System.Drawing.Point(112, 88)
        Me.optCapturable.Name = "optCapturable"
        Me.optCapturable.Size = New System.Drawing.Size(96, 16)
        Me.optCapturable.TabIndex = 18
        Me.optCapturable.TabStop = True
        Me.optCapturable.Text = "Capturable"
        '
        'chkIsActive
        '
        Me.chkIsActive.Location = New System.Drawing.Point(112, 56)
        Me.chkIsActive.Name = "chkIsActive"
        Me.chkIsActive.Size = New System.Drawing.Size(120, 16)
        Me.chkIsActive.TabIndex = 17
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(8, 226)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(96, 16)
        Me.Label6.TabIndex = 16
        Me.Label6.Text = "Max Total"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 186)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(96, 16)
        Me.Label5.TabIndex = 15
        Me.Label5.Text = "Max Per Turn"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 89)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(96, 16)
        Me.Label4.TabIndex = 14
        Me.Label4.Text = "May Be Captured"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 147)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96, 16)
        Me.Label3.TabIndex = 13
        Me.Label3.Text = "Capture Event"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 56)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(96, 16)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "Is Active"
        '
        'lblDeploymentZoneName
        '
        Me.lblDeploymentZoneName.Location = New System.Drawing.Point(8, 19)
        Me.lblDeploymentZoneName.Name = "lblDeploymentZoneName"
        Me.lblDeploymentZoneName.Size = New System.Drawing.Size(96, 16)
        Me.lblDeploymentZoneName.TabIndex = 10
        Me.lblDeploymentZoneName.Text = "Zone Name"
        '
        'txtDeploymentZoneName
        '
        Me.txtDeploymentZoneName.Location = New System.Drawing.Point(112, 16)
        Me.txtDeploymentZoneName.Name = "txtDeploymentZoneName"
        Me.txtDeploymentZoneName.Size = New System.Drawing.Size(120, 20)
        Me.txtDeploymentZoneName.TabIndex = 9
        Me.txtDeploymentZoneName.Text = "Unnamed"
        '
        'btnOk
        '
        Me.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOk.Location = New System.Drawing.Point(168, 272)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.Size = New System.Drawing.Size(75, 23)
        Me.btnOk.TabIndex = 23
        Me.btnOk.Text = "OK"
        '
        'frmDeploymentZone
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(264, 302)
        Me.Controls.Add(Me.pnlObjectiveProperties)
        Me.Controls.Add(Me.btnOk)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmDeploymentZone"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Deployment Zone"
        Me.pnlObjectiveProperties.ResumeLayout(False)
        Me.pnlObjectiveProperties.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef item As cmplib01.DeploymentZone, ByRef game As cmplib01.CampaignerGameData)

        Me.New()

        ptrCGD = game
        ptrDeploymentZone = item
        PopulateProperties()

    End Sub

    Private Sub PopulateProperties()
        ' populates the textboxes with the deploymentzone properties
        Try
            txtDeploymentZoneName.Text = ptrDeploymentZone.ZoneName
            Select Case ptrDeploymentZone.CaptureEvent
                Case cmplib01.CaptureEvent_cgd.ChangeOwnership
                    cboCaptureEvent.Text = "Changes Ownership"
                Case cmplib01.CaptureEvent_cgd.Hold
                    cboCaptureEvent.Text = "Hold"
                Case cmplib01.CaptureEvent_cgd.Destroyed
                    cboCaptureEvent.Text = "Destroyed"
            End Select
            If ptrDeploymentZone.Capturable Then
                optCapturable.Checked = True
            Else
                optNotCapturable.Checked = True
                cboCaptureEvent.Enabled = False
            End If
            chkIsActive.Checked = ptrDeploymentZone.Active
            txtMaxDeploymentPerTurn.Text = ptrDeploymentZone.MaxDeploymentPerTurn.ToString
            txtMaxTotalDeployment.Text = ptrDeploymentZone.MaxTotalDeploy.ToString
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Function UpdateProperties() As Boolean
        ' saves the text inputs back into the provided deploymentzone
        If ValidateValues() Then
            ' update the values to the provided object
            Try
                With ptrDeploymentZone
                    .ZoneName = txtDeploymentZoneName.Text
                    ' capturable is set when the user presses the radio buttons
                    ' captureevent is set when the use clicks the combo box
                    .Active = chkIsActive.Checked
                    .MaxDeploymentPerTurn = CType(txtMaxDeploymentPerTurn.Text, Short)
                    .MaxTotalDeploy = CType(txtMaxTotalDeployment.Text, Short)

                    Select Case cboCaptureEvent.Text
                        Case "Changes Ownership" : .CaptureEvent = cmplib01.CaptureEvent_cgd.ChangeOwnership
                        Case "Hold" : .CaptureEvent = cmplib01.CaptureEvent_cgd.Hold
                        Case "Destroyed" : .CaptureEvent = cmplib01.CaptureEvent_cgd.Destroyed
                    End Select

                End With
            Catch ex As Exception
                HandleException(c_Module, ex)
            End Try
        Else
            Return False
        End If

        Return True

    End Function

    Private Function ValidateValues() As Boolean
        ' catch any violations
        If Not IsNumeric(txtMaxDeploymentPerTurn.Text) Then
            MessageBox.Show("You must provide a numeric value for Max Deployment Per Turn.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False
        End If
        If Not IsNumeric(txtMaxTotalDeployment.Text) Then
            MessageBox.Show("You must provide a numeric value for Max Total Deplolyment.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False
        End If

        ' values are valid
        Return True

    End Function

    Public ReadOnly Property CancelPressed() As Boolean
        Get
            Return m_CancelPressed
        End Get
    End Property

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        m_CancelPressed = False
        If UpdateProperties() Then ' return control
            Me.Hide()
        End If
    End Sub

    Private Sub optCapturable_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optCapturable.CheckedChanged
        If Not ptrDeploymentZone Is Nothing Then ptrDeploymentZone.Capturable = optCapturable.Checked
    End Sub

End Class
